/*
 * @lc app=leetcode.cn id=11 lang=javascript
 *
 * [11] 盛最多水的容器
 */

// @lc code=start
/**
 * @param {number[]} height
 * @return {number}
 */
var maxArea = function (heightArr) {
    /* 双指针，两边往中间，宽缩小，高增大 */
    let left = 0
    let right = heightArr.length - 1
    let ans = 0
    while (left < right) {
        let width = right - left
        let height = 0
        if (heightArr[left] < heightArr[right]) {
            height = heightArr[left]
            left++
        } else {
            height = heightArr[right]
            right--
        }
        let volume = width * height
        ans = ans < volume ? volume : ans
    }
    return ans
};
// @lc code=end